import * as vscode from 'vscode';
import { context } from '../utils/context';
import { globalData } from '../../globalData';

const keys = [
    'dependencies', 'package', 'workspace', 'test-dependencies', 'ffi.c', 'profile',
    //package
    'cjc-version', 'name', 'description', 'version', 'compile-option', 'link-option', 'output-type', 'src-dir', 'target-dir', 'package-configuration',
    //workspace
    'members', 'build-members', 'test-members', 'compile-option', 'link-option', 'target-dir', 'coo', 'doo',
    //profile
    'build', 'test', 'customized-option'
];

export class tomlCompletionItem {
    private static context: context;
    private static arr: vscode.CompletionItem[] = [];
    static create(mark: string, context: context) {
        this.arr = [];
        this.context = context;
        const tag = mark.toLowerCase(),
            arr = keys.filter((i) => i.startsWith(tag));
        this.newItems(arr);
        return this.arr;
    }

    private static newItems(marks: string[]) {
        for (const mark of marks) {
            let insertText = `${mark} = ""`;
            if (mark === 'cjc-version' && globalData.sdkVersion.length > 0) {
                insertText = `${mark} = "${globalData.sdkVersion}"`;
            }
            const item = {
                label: mark,
                insertText: insertText,
                range: this.context.importRange,
                kind: vscode.CompletionItemKind.Constant
            };
            this.arr.push(item);
        }
    }
}